<template>
	<view class="contain cu-card">
		<view class="cu-item contenBox">
			<view class="input-row border contenBox-item ">
				<text class="text-gray leftCol start-mark">车牌号：</text>
				<picker @change="bindPickerChange" class="cuspicker" style="position: relative;" range-key="LicensePlateNO" :value="index.truck"
				 :range="truckList" data-type="truck">
					<view class="picker cuspicker_item ">
						{{truckList[index.truck].LicensePlateNO ||"" }}
					</view>
				</picker>
			</view>
			<text class="cuIcon-right text-blue" style="position: relative;left: 305px;top: -35px;"></text>
		</view>
		<view class="signIn" :style="{ 'background-color': isSign ? '#9FACA3' : '#27B148' }" :disabled="isSign" @click="sign"><text>岗亭扫描</text></view>
		<view v-if="scanTime" class="center" style="font-size: 18px;">
			门岗扫描时间：<text style="color: red;">{{scanTime}}</text>
		</view>
		<view v-if="scanTip" class="center" style="font-size: 18px;">
			<text style="color: red;">{{scanTip}}</text>
		</view>
	</view>
</template>

<script>
	import moment from 'moment'
	export default {
		data() {
			return {
				openid: '',
				truckList: [],
				isSign: true,
				pageType: '',
				index: {
					truck: 0,
				},
				scanTime:'',
				scanTip:'',
			};
		},
		onLoad(e) {
			console.log('eeee', e)
			this.pageType = e.page
		},
		mounted() {
			const session = uni.getStorageSync('session');
			this.openid = session.openid;
			console.log('id', session)
			// this.getDetail(session.openid);
			this.getTruckInfo()
		},
		methods: {
			getDetail(id) {
				this.$store.dispatch('uni/GetCZSignInfoList', {
					openid: id
				}).then(res => {
					console.log('ressss', res);
					this.isSign = !res.Data.IsEnableCZSign;
				});
			},
			getScanState(){
				this.$store.dispatch('uni/GetGateScanState',{
					LicensePlateNO:this.truckList[this.index.truck].LicensePlateNO,
					// LicensePlateNO:'皖AF6390',
				}).then(res=>{
					console.log('res====',res)
					this.scanTime=''
					this.scanTip=''
					switch(res.Data.state){
						case 0:
							this.isSign=false
							break;
						case 2:
							this.isSign=true
							this.scanTime=moment(res.Data.scanTime).format('MM-DD HH:mm:ss')
							break;
						case 3:
							this.isSign=true
							this.scanTip=res.Data.scanTip
							break
					}
				})
			},
			getTruckInfo() {
				uni.showLoading({
					title: '加载中'
				});
				this.$store.dispatch('uni/GetTruckList', {
					openid: this.openid
				}).then(res => {
					uni.hideLoading()
					this.truckList = res.Data || [];
					if (res.Data.length === 0) {
						uni.showToast({
							title: '暂无车牌数据',
							duration: 2000
						});
						return
					}
					this.getScanState()
				}).catch(() => uni.hideLoading());
			},
			bindPickerChange(e) {
				console.log('bindPickerChange???')
				const {
					type
				} = e.currentTarget.dataset;

				let _index = e.detail.value
				this.index[type] = e.detail.value;
				this.getScanState()
			},
			sign() {
				if (this.isSign) return
				uni.scanCode({
					success: res => {
						console.log('resssssssss',res,this.truckList[this.index.truck].LicensePlateNO)
						if (res) {
							this.$store
								.dispatch('uni/ScanAreaQR', {
									openid: this.openid,
									plateNo:this.truckList[this.index.truck].LicensePlateNO,
									// plateNo:'皖AQ2937',
									QRcodeID: res.result
								})
								.then(v => {
									console.log('v--------',v)
									if (v.Code === 0) {
										// this.isSign = !v.Data.IsEnableCZSign
										uni.showToast({
											title: v.Message,
											duration: 1500
										});
										setTimeout(() => {
											this.getScanState()
										}, 1500);
									}
								});
						}
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.contain {
		position: relative;
		height: 100vh;
		width: 100vw;
	}

	.contenBox {
		padding: 10px 0px 10px 10px;

		&-item {
			height: 50px;

		}

		&-border {
			border: 1px solid #DADADA;
			border-radius: 5px;
			width: 70vw;
			height: 33px;
			line-height: 33px;
			padding-left: 6px;
		}

		.leftCol {
			width: 90px;
		}

		.input-row {
			padding: 10px 15px;

		}

		.start-mark::before {
			content: '*';
			color: red;
			position: absolute;
			//top: 7px;
			left: 6px;
			font-size: 20px;

		}

		.cuspicker_item {
			width: 237px;
			height: 33px;
			line-height: 33px;
		}
	}

	.signIn {
		position: absolute;
		left: 50%;
		top: 30%;
		transform: translate(-50%, -50%);
		z-index: 10;
		width: 120px;
		height: 120px;
		border-radius: 50%;
		background-color: #27b148;
		color: #ffffff;
		font-size: 16px;
		text-align: center;
		box-shadow: 0 3px 2px #90a19a;

		text {
			line-height: 120px;
			font-weight: bold;
		}
	}
.center{
	position: absolute;
	top: 50%;
	left: 20%;
	// left: 50%;
	// transform: translate(-50%,-50%);
}
</style>
